import axios from 'axios'
import { useUserStore } from '@/stores'

const baseURL = 'http://localhost:8080'

const http = axios.create({
  // 1.基础地址，超时时间
  baseURL,
  timeout:10000
})


//请求拦截器
http.interceptors.request.use(
  (config) => {
    // 2.携带token
    const useStore = useUserStore()
    if(useStore.token) {
      config.headers.token = useStore.token
      // console.log(config)
    }
    return config
  },
  (err) => Promise.reject(err)
)


export default http
export { baseURL}